﻿using BasicInformation.Domain;
using MediatR;
using SCM.API.Read.Application.Command.Purchase;
using SCM.API.Read.Application.Command.Sale;
using SCM.ErrorCode;
using SCM.Infrastructure.Implement;

namespace SCM.API.Read.Application.Handler.Sale
{
    public class GetClientHandler : IRequestHandler<GetClientCommand, APIResult<ClientModel>>
    {
        DatabaseContext db;

        public GetClientHandler(DatabaseContext db)
        {
            this.db = db;
        }

        public  Task<APIResult<ClientModel>> Handle(GetClientCommand request, CancellationToken cancellationToken)
        {
            var result = new APIResult<ClientModel>();
            var supplierName = db.SqlSugar.Queryable<ClientModel>().Where(s => s.ClientId == request.ClientId && s.IsDel == false);

            if (supplierName == null)
            {
                result.Code = APIEnum.Fail;
                result.Msg = "客户不存在";
                return  Task.FromResult(result);
            }

            result.Code = APIEnum.Success;
            result.Msg = "查询客户成功";
            result.Datas = supplierName.ToList();
            return  Task.FromResult(result);
        }
    }
}
